@include('admin._include.header')
<style>
    .layui-form-label{
        padding: 9px 10px;
        width: 90px;
    }
</style>
<body class="auth-user">
<div class="layui-fluid">
    <div class="layui-row larryms-panel auth-user-add">
        <form class="layui-form" method="post">
            <div class="layui-form-item">
                <label class="layui-form-label">管理员姓名</label>
                <div class="layui-input-block">
                    <input type="text" name="name" lay-verify="required" placeholder="请填写管理员姓名"  value="{{$manager->name}}" autocomplete="off" class="layui-input larry-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">管理员权限组</label>
                <div class="layui-input-block">
                    <select name="gid" lay-verify="required" lay-filter="type_select">
                        <option value="">请选择权限组</option>
                        @foreach($groupList as $k => $item)
                            <option @if($manager->gid == $item->id) selected @endif value="{{$item->id}}">{{$item->name}}</option>
                        @endforeach
                    </select>
                </div>
            </div>

            @if(blank($manager->password))
            <div class="layui-form-item">
                <label class="layui-form-label">管理员密码</label>
                <div class="layui-input-block">
                    <input type="text" name="password" lay-verify="required"  placeholder="请填写管理员密码"  value="" autocomplete="off" class="layui-input larry-input">
                </div>
            </div>
            @endif

            <div class="layui-form-item">
                <label class="layui-form-label">管理员联系方式</label>
                <div class="layui-input-block">
                    <input type="text" name="phone"  placeholder="请填写管理员手机号"  value="" autocomplete="off" class="layui-input larry-input">
                </div>
            </div>

            <div class="layui-form-item" style="text-align: center">
                <input type="hidden" name="id" value="{{$manager->id}}">
                <button class="layui-btn" lay-submit lay-filter="add_manager">确定</button>
            </div>

        </form>
    </div>
</div>


<script>
    layui.config({
        base: "/plugin/layuiadmin/" //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form'], function(){
        var $ = layui.jquery,
        form = layui.form;

        form.on('submit(add_manager)', function(data) {
            var index = layer.load(1);
            $.ajax({
                url:"{{url('auth/edit-manager')}}",
                dateType:'json',
                data:data.field,
                type:'post',
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                success:function (res) {
                    layer.close(index);
                    layer.msg(res.message);
                    if(res.status == SUCCESS){
                        var iframe = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(iframe); //再执行关闭
                    }

                }
            });

            return false;
        });

    });


</script>

</body>
@include('admin._include.footer')